# app.py
import tkinter as tk
from tkinter import ttk
from database import Database
from analysis import FinancialAnalysis
# 从新的模块导入
from ui.record_page import RecordPage
from ui.view_export_page import ViewExportPage
from ui.budget_page import BudgetPage
from ui.analysis_page import AnalysisPage

class AccountingApp:
    def __init__(self, root):
        self.root = root
        self.root.title("个人记账本 - 专业版")
        self.root.geometry("1200x800")
    
        # 设置图标
        try:
            self.root.iconbitmap("accounting_icon.ico")
        except:
            pass
    
        # 初始化数据库和分析模块
        self.db = Database()
        self.analysis = FinancialAnalysis(self.db)
        
        # 创建笔记本控件（标签页）
        self.notebook = ttk.Notebook(self.root)
        self.notebook.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
        
        # 初始化新的UI组件
        self.record_page = RecordPage(self.notebook, self.db, self.analysis)
        self.notebook.add(self.record_page.frame, text="记账")
        
        self.view_export_page = ViewExportPage(self.notebook, self.db, self.analysis)
        self.notebook.add(self.view_export_page.notebook, text="查看与导出")
        
        # 添加预算管理页面
        self.budget_page = BudgetPage(self.notebook, self.db, self.analysis)
        self.notebook.add(self.budget_page.frame, text="预算管理")
        
        # 添加统计分析页面
        self.analysis_page = AnalysisPage(self.notebook, self.db, self.analysis)
        self.notebook.add(self.analysis_page.frame, text="统计分析")
        
        # 加载初始数据
        self.view_export_page.refresh_transactions()
        
    def refresh_view_page(self):
        """刷新查看页面"""
        self.view_export_page.refresh_transactions()